<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>工单审核</title>
	</head>
	<body>
		<form class="layui-form" action="#" lay-filter="apply-form2" id="applyForm2">
			<input type="hidden" name="orderId" />
			<!--<input type="hidden" name="status"/>
			<input type="hidden" name="isApprovaled" />-->
			<input type="hidden" name="managerNo">
			<div class="layui-form-item">
				<label class="layui-form-label">工单处理人:</label>
				<div class="layui-form-mid layui-word-aux">
					<input type="hidden" name="thisHandler" id="thisHandler">
					<div id="currentHandler"></div>
				</div>
			</div>
			<div class="layui-form-item" id="applyForm2ContactName">
				<label class="layui-form-label">联系人:</label>
				<div class="layui-input-inline" style="width:400px;">
					<input type="text" name="contactName" id="contactName" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item" id="applyForm2CustomerPhone">
				<label class="layui-form-label">联系电话:</label>
				<div class="layui-input-inline" style="width:400px;">
					<input type="text" name="customerPhone" id="customerPhone" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item" id="applyForm2CustomerAddress">
				<label class="layui-form-label">客户地址:</label>
				<div class="layui-input-inline" style="width:400px;">
					<input type="text" lay-verify="customerAddress" name="customerAddress" id="customerAddress" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label"><span class="redColor">*</span>是否同意:</label>
				<div class="layui-input-block" style="width:400px;">
					<input type="radio" name="isUrgent" value="0" title="是" checked="">
					<input type="radio" name="isUrgent" value="1" title="否">
				</div>
			</div>
			<div class="layui-form-item" id="selectEm">
				<label class="layui-form-label"><span class="redColor">*</span>选择工程师:</label>
				<div class="layui-input-inline" style="width:400px;">
					<input type="text" name="handler" lay-verify="handler" placeholder="请选择工程师" class="layui-input" readonly="readonly">
					<input type="hidden" name="handlerNo" />
					<input type="hidden" name="handlerDept" />
				</div>
				<div class="layui-form-mid layui-word-aux">
					<i class="layui-icon layui-icon-add-circle" style="font-size:28px" id="selectUser"></i>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span class="redColor">*</span>审批意见:</label>
				<div class="layui-input-block" style="width:400px">
					<textarea placeholder="请输入审批意见" class="layui-textarea" name="applyDesc" lay-verify="applyDesc"></textarea>
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit="" lay-filter="applybtnByManager">提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>

		<script type="text/javascript">
			initApplyForm();
			function initApplyForm() {
				var form = layui.form
				window.applyForm = form.render(null, 'apply-form2');
				window.applyForm.verify({
					handler: function(value, item) {
						var isUrgent = $('#applyForm2 input[name="isUrgent"]:checked ').val();
						var _$selectEm = $("#selectEm");
						console.log(isUrgent);
						if (isUrgent == 0 && _$selectEm.css('display') != "none") {
							if (value.trim() == '') {
								return '请选择工程师';
							}
						}
					},
					applyDesc: function(value, item) {
						if (value.trim() == '') {
							return '请输入审批意见';
						}
					},
					customerAddress: function(value, item) {
						if (value.trim() == '') {
							return '请填写客户地址!';
						}
					}

				});
				
				window.applyForm.on('radio', function(data) {
					var orderStatus = $('#applyForm2').find('input[name="status"]').val();
					var isApprovaled = $('#applyForm2').find('input[name="isApprovaled"]').val();
					var managerNo = $('#applyForm2').find('input[name="managerNo"]').val();
					if ($(this).val() == 0) {
// 						if (isApprovaled == 0 || orderStatus == "3") {
// 							$('#selectEm').show();
// 						}
							if (managerNo.toUpperCase() == window.empCode.toUpperCase()) {
								$('#selectEm').show();
							}
					} else {
						$('#selectEm').hide();
					}
				});
					
				window.applyForm.on('submit(applybtnByManager)', function(data) {
					var _index = layer.load(3);
					var content = data.field;

					if (!window._gettingCustomerLocation) {
						layer.msg('请填写正确的客户地址!');
						return false;
					}
					//		console.log(content);
					$.ajax({
						url: window.basePath + '/order/applyOrderByManager',
						method: 'POST',
						headers: {"token" : window.token},
						dataType: 'json',
						data: content,
						success: function(data) {
							layer.close(_index);
							if (data.success) {
								layer.closeAll();
								$(document).trigger('applyRefresh');
							}
							layer.msg(data.message);
						},
						error: function(data) {
							layer.close(_index);
							layer.msg('网络异常！');
						}
					});

					return false;
				});

				//选择工程师界面
				$('#selectUser').on('click', function() {
					showDialog({
						title: '工单审批',
						template: window.basePath + '/admin/views/sys/usersSelect.html',
						showbtns: true,
						width: 750,
						height: 550,
						yes: function(index) {
							var checkTempData = window.userTable.checkStatus('userTable');
							var data = checkTempData.data;
							if (data && data.length > 0) {
								if (data.length > 1) {
									layer.msg('只能选择一条数据');
								} else {
									$('#applyForm2').find('input[name="handler"]').val(data[0].EmpName);
									$('#applyForm2').find('input[name="handlerNo"]').val(data[0].EmpCode);
									$('#applyForm2').find('input[name="handlerDept"]').val(data[0].OrgName);
									layer.close(index);
								}
							}
						}
					});
				});
			}
		</script>
	</body>
</html>
